## Figure A8: Clustering of Closing Dates by Day of Month and Neighborhood Race

## install.packages(c("tidyverse"))
## library(tidyverse)

## SET WORKING DIRECTORY HERE
## setwd()

## Loading data
## load("dta.RData")

clustering_days_of_month_white = dta %>%
  filter(!is.na(close_day_of_month)) %>%
  filter(!is.na(white_third)) %>%
  mutate(n = 1,
         close_day_of_month = factor(close_day_of_month)) %>%
  group_by(white_third, close_day_of_month) %>%
  summarise(n_requests_closed = sum(n, na.rm = TRUE)) %>%
  ggplot(aes(x = factor(close_day_of_month), y = n_requests_closed, fill = factor(white_third))) +
  geom_bar(stat = "identity", position = "dodge") +
  scale_x_discrete(labels = c("1", "", "", "", "", "", "", "",
                              "", "", "", "", "", "", "15", "",
                              "", "", "", "", "", "", "", "",
                              "", "", "", "", "", "30", "")) +
  scale_fill_brewer(name = "% White Tercile", palette = "Blues", labels = c("Top", "Middle", "Bottom")) +
  labs(x = "Day of Month",
       y = "# of Requests Closed") +
  theme_classic() +
  theme(legend.position = "bottom",
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "black"))